package Railroad.GUI;

import Railroad.Communication.CommDriver;
import Railroad.ObsadzovacCiest;
import Railroad.TrackUpdateListener;
import Railroad.Zoznam;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

public class MainWindow extends javax.swing.JFrame implements TrackUpdateListener {

    public MainWindow(Zoznam z, ObsadzovacCiest o, RiadenieNavestidiel r) {
        initComponents();
        setResizable(false);
        railroadPanel.setZoznam(z); 
        railroadPanel.setObsadzovac(o);
        railroadPanel.setRiadenie(r);
       
        
    //  RiadenieNavestidiel r=new RiadenieNavestidiel(z);
        
       // r.vratFrame();
       // Semafor sem=new Semafor(r.getList());
        //sem.setVisible(true);
       
        JMenuBar menuBar = new JMenuBar();
        // Add the menubar to the frame
        setJMenuBar(menuBar);

        // Define and add two drop down menu to the menubar
        JMenu fileMenu = new JMenu("Menu");

        menuBar.add(fileMenu);

        ActionListener ordermethod = new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                railroadPanel.setRus(true);
            }
        };
        // Create and add simple menu item to one of the drop down menu
        JMenuItem item = new JMenuItem("RC");
        item.addActionListener(ordermethod);
        fileMenu.add(item);

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        railroadPanel = new Railroad.GUI.RailroadPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout railroadPanelLayout = new javax.swing.GroupLayout(railroadPanel);
        railroadPanel.setLayout(railroadPanelLayout);
        railroadPanelLayout.setHorizontalGroup(
            railroadPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 800, Short.MAX_VALUE)
        );
        railroadPanelLayout.setVerticalGroup(
            railroadPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 600, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(railroadPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(railroadPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private Railroad.GUI.RailroadPanel railroadPanel;
    // End of variables declaration//GEN-END:variables

    public void setCommunication(CommDriver communication) {
        railroadPanel.setCommunication(communication);
    }

    @Override
    public void onUpdate() {
        railroadPanel.repaint();
    }
}
